use std::net::{Ipv4Addr, IpAddr};
use std::fs::File;
use std::io::Read;

pub fn main(){
    // let ip: IpAddr = "127.0.0.1qw".parse().unwrap();
    // println!("{}", ip.is_ipv6());

    let path = "C:\\Users\\frank\\Desktop\\新建文本文档.txt";
    let cont = read_file(path).unwrap_or("读取文件失败".to_string());
    println!("content={}", cont);
}
fn read_file(path: &str)->Result<String, std::io::Error>{
    let mut s = String::new();
    let res = File::open(path);
    let mut f = match res {
        Ok(fi)=> fi,
        Err(e)=> return Err(e),
    };
    match f.read_to_string(&mut s) {
        Ok(size)=>Ok(s),
        Err(e) => Err(e),
    }
    // 第二种写法
    // File::open(path)?.read_to_string(&mut s)?;
    // Ok(s)
}